package com.zwface.demo.greendao;

import com.zwface.demo.App;
import com.zwface.demo.comm.comm;
import com.zwface.demo.model.db.Attendance;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

/**
 * created by      张中文
 * on:             2020/4/28 8:46
 * 描述：考勤数据库操作
 */
public class AttendanceManager
{
    static AttendanceDao attendanceDao = App.getInstance().getDaoSession().getAttendanceDao();

    public static Long addAttendance(Attendance attendance){
        return attendanceDao.insert(attendance);
    }

    public static List<Attendance> queryAllAttendance(){
        return attendanceDao.queryBuilder().list();
    }

    /**
     * 查询今天签到的记录
     * @return
     */
    public static Map<String,Attendance> queryAttendancesToday(){
        int zomeTime = TimeZone.getDefault().getRawOffset();////今天零点零分零秒的毫秒数
        List<Attendance> list = attendanceDao.queryBuilder().where(AttendanceDao.Properties.BuildTime.ge(zomeTime)).list();
        Map<String,Attendance> map = new HashMap<>();
        //去重，去除学生号相同的
        for (Attendance attendance:list){
            map.put(attendance.getStuNo(),attendance);
        }
        return map;
    }
}
